<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<div class="modal fade" id="ocean-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width: 1000px; height: auto">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <c:choose>
                    <c:when test="${entity.id != null && entity.id!= ''}">
                        <h4 class="modal-title">编辑菜单</h4>
                    </c:when>
                    <c:otherwise>
                        <h4 class="modal-title">新增菜单</h4>
                    </c:otherwise>
                </c:choose>
            </div>
            <div class="modal-body">
                <div class=" form">
                    <form class="cmxform form-horizontal tasi-form" id="menu_form" method="post"
                          data-url="resources/entity"
                          data-class="com.ocean.core.entity.Menu">
                        <input type="hidden" id="entity_id" name="id" value="${entity.id}">
                        <div class="form-group">
                            <label for="name" class="control-label col-lg-2">名称 </label>
                            <div class="col-lg-10">
                                <input class="form-control" id="name" name="name" type="text" placeholder="名称"
                                       value="${entity.name}"
                                       required/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="url" class="control-label col-lg-2">链接地址 </label>
                            <div class="col-lg-10">
                                <input class="form-control" id="url" name="url" type="text" placeholder="链接地址"
                                       value="${entity.url}"
                                       required/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="ord" class="control-label col-lg-2">排序 </label>
                            <div class="col-lg-10">
                                <input class="form-control" id="ord" name="ord" type="number" placeholder="排序"
                                       value="${entity.ord}"
                                       required/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="parent" class="control-label col-lg-2">上级菜单 </label>
                            <div class="col-lg-10">
                                <select class="form-control" id="parent" name="parent">

                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-lg-offset-2 col-lg-10">
                                <button class="btn btn-success" type="button" onclick="formSubmit(validator)">Save
                                </button>
                                <button class="btn btn-default" type="button" data-dismiss="modal">Cancel</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="application/javascript">
    $("#parent").empty();
    $("#parent").append('<option value="">ROOT</option>');
    $.each(menuData, function (index, item) {
        if (item.id == '${entity.parent}') {
            $("#parent").append('<option value="' + item.id + '" selected="selected">' + item.name + '</option>');
        } else {
            $("#parent").append('<option value="' + item.id + '">' + item.name + '</option>');
        }
    });
</script>
<script type="application/javascript">
    var validator = $("#menu_form").validate();
</script>
